<template>
  <BasicModal v-bind="$attrs" @register="register" showFooter :title="getTitle" width="70%" :showOkBtn="false"
    :loading="loading">
    <!-- 审批进度 -->
    <div style="width: 100%; height: 450px">
      <!-- v-on="gridEvents" overflow: hidden -->
      <vxe-grid ref="tableRef" v-bind="gridOptions">
        <template #toolbar_buttons>

        </template>

      </vxe-grid>


    </div>

  </BasicModal>
</template>
<script lang="ts" setup>
import { ref, computed, unref, h, toRaw, reactive } from 'vue';

import {
  BasicTableProps,
  VxeGridInstance
} from '@/components/VxeTable';

import { fapiaoColumns } from './role.data';
import { BasicModal, useModalInner } from '@/components/Modal';

import { BasicTree, TreeItem } from '@/components/Tree';
import { approveCreateBefore, approveSubmit, shouKuanQueRenItemList } from '@/api/heng/ywManage';

import { Modal, Timeline, TimelineItem } from 'ant-design-vue';

import { useMessage } from "@/hooks/web/useMessage";

const emit = defineEmits(['success', 'register']);
const isUpdate = ref(true);
const treeData = ref<TreeItem[]>([]);
const { createMessage } = useMessage();
const mouldMainId = ref("");

const applyViewShow = ref(false);
const visible = ref(false);
const msgList = ref([]);

const tableRef = ref<VxeGridInstance>();

const gridOptions = reactive<BasicTableProps>({
  // keepSource: true,
  border: true,
  showOverflow: true,
  size: 'mini',
  height: 'auto', // 'auto'
  columns: fapiaoColumns,
  exportConfig: {},
  filterConfig: {
    remote: true,
  },
  toolbarConfig: {
    slots: {
      buttons: 'toolbar_buttons',
    },
    refresh: true,
  },

  pagerConfig: {
    enabled: false
  },

});


const startNodeList = ref([]);
const loading = ref(false);
const dataList = ref([]);

const dataJson = ref({});//审批发起后 返回的数据

const [register, { setModalProps, closeModal }] = useModalInner(async (data) => {
  //打开弹层后的回调
  // resetFields();
  setModalProps({ confirmLoading: false });

  // dataList.value = data.selectList;
  // console.log(data.record);

  tableRef.value?.reloadData([]);
  let dJson = { skqrNo: data.record.orderNo };

  shouKuanQueRenItemList(dJson).then(res => {
    if (res && res.code == 200) {
      let list = res.data
      tableRef.value?.reloadData(list);
    } else {
      createMessage.error(res.message);

    }
    dataJson.value = res.data;
  })

});

const getTitle = computed(() => ('发票核销明细信息'));


function applyViewOpen() {
  applyViewShow.value = true;
}

function applyViewClose() {
  applyViewShow.value = false;
}

//async function handleSubmit()

const handleSubmit = () => {
  try {

    let data = unref(dataJson.value);

    console.log(data);
    loading.value = true;
    approveSubmit(data).then(res => {
      loading.value = false;
      sunccFn(res)
    })


  } catch (e) {
    console.log(e)
  } finally {
    setModalProps({ confirmLoading: false });

  }
}



function sunccFn(result) {
  if (result && result.code == 200) {
    applyViewClose();
    createMessage.success(result.message);
    closeModal()
    emit('success');
  } else {
    createMessage.error(result.message);
  }

}

function cancelFn() {
  //  tableRef.value.clearValidate();
}

function handleOk() {
  visible.value = false;
}

</script>
<style lang="less">
.item-row {
  margin: 0 auto;

  //padding-left: 5%;
  .ant-form-item-label {
    flex: 0 0 28.5%;
    max-width: 28.5%;
  }
}

.lqfp-8 {
  //padding-left: 9% !important;

}
</style>
